#include <iostream>
#include <cstring> // 用于strcpy等字符串函数
#include "function.h"
#include <limits> // 新增：用于numeric_limits

void Cover()
{
    while (1)
    {
    cout << "----------请输入要进行的操作------------" << endl; 
    cout << "1.增" << endl; 
    cout << "2.删" << endl; 
    cout << "3.改" << endl; 
    cout << "4.查" << endl; 
    cout << "5.查看链表" << endl;
    cout << "0.退出" << endl;
    cout << "---------------------------------------" << endl; 
        int choice;
        cin >> choice;

        // 检查输入是否成功
        if (cin.fail()) {
            // 清除错误状态
            cin.clear();
            // 忽略当前行的所有剩余输入
            cin.ignore(numeric_limits<streamsize>::max(), '\n');
            cout << "输入错误，请输入数字！" << endl;
            // 跳过switch，继续下一轮循环
            continue;
        }

        switch(choice)
        {
            case 1:
                // cout << "增" << endl;
                add_Student();
                break;
            case 2:
                cout << "删" << endl;
                del_Student();
                break;
            case 3:
                cout << "改" << endl;
                change_Student();
                break;
            case 4:
                cout << "查" << endl;
                search_Student();
                break;
            case 5:
                cout << "查看链表" << endl;
                show_Student();
                break;
            case 0:
                cout << "退出" << endl;
                return;
            default:
                cout << "输入错误,请输入0-5之间的数字!" << endl;
                // break;
        }
    }
}


int main()
{   
    initList();
    Studentlist *p1 = new Studentlist("小明", 18,"男", NULL);
    Studentlist *p2 = new Studentlist("小红", 18,"女", NULL);
    join_Student(p1);
    join_Student(p2);


    // 显示封面
    Cover();


    return 0;
}